import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */

//配置路由数组
// '/'表示views目录文件夹
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},

//测试页面
{
  path: '/',
  component: Layout,
  children: [{
    path: 'homePage',
    name: 'homePage',
    component: () => import('@/views/homePage/homePage'),
    meta: {
      title: '首页', icon: 'homePage'
    }
  }]
},

// 自己添加的路由
{
  path: "/car",
  component: Layout,
  meta: {
    title: '停车场管理',
    icon: 'park'
  },
  children: [
    // 停车管理
    {
      path: 'parklot',  //url路径
      name: 'parklot',
      component: () => import('@/views/car/parklot/parklot'), // 懒加载，此处写所添加文件的路径
      meta: {
        title: '停车管理', icon: 'parklot' //配置选项可配置测试名称和图标
      }
    },
    // 车位管理
    {
      path: 'carlot',
      name: 'carlot',
      component: () => import('@/views/car/carlot/carlot'),
      meta: {
        title: '车位管理', icon: 'carlot'
      }
    }
  ]
},
// 数据采集菜单
{
  path: "/pre",
  component: Layout,
  meta: {
    title: '数据采集',
    icon: 'pre'
  },
  children: [
    {
      path: 'traffic_situation',  //url路径
      name: 'traffic_situation',
      component: () => import('@/views/pre/traffic_situation'), // 懒加载，此处写所添加文件的路径
      meta: {
        title: '交通态势', icon: 'traffic' //配置选项可配置测试名称和图标
      }
    },
    {
      path: 'his_weather',
      name: 'his_weather',
      component: () => import('@/views/pre/his_weather'),
      meta: {
        title: '历史天气数据', icon: 'weather'
      }
    },
    {
      path: 'people_flowrate',
      name: 'people_flowrate',
      component: () => import('@/views/pre/people_flowrate'),
      meta: {
        title: '人流量', icon: 'people_flow'
      }
    }
  ]
},
// 车位余量与车位检测
{
  path: "/carPre",
  component: Layout,
  meta: {
    title: '车位余量',
    icon: 'left'
  },
  children: [
    {
      path: 'carCheck',  //url路径
      name: 'carCheck',
      component: () => import('@/views/carPre/carCheck'), // 懒加载，此处写所添加文件的路径
      meta: {
        title: '余量检测', icon: 'check' //配置选项可配置测试名称和图标
      }
    },
    {
      path: 'carPre',  //url路径
      name: 'carPre',
      component: () => import('@/views/carPre/carPre'), // 懒加载，此处写所添加文件的路径
      meta: {
        title: '余量预测', icon: 'carPre' //配置选项可配置测试名称和图标
      }
    },
  ]
},
// 404 page must be placed at the end !!!
{
  path: '*',
  redirect: '/404',
  hidden: true
}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
